﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Public.Api.Controllers
{
    [EnsureHttps]
    public class BusinessesController : Controller
    {
        public ActionResult GetTypesAndCategories()
        {
            var model = DataAccess.Businesses.GetTypesAndCategories();
            return new JsonXmlResult(model);
        }

        public ActionResult ListBusinesss(Adams.Public.DataTransfer.Businesses.ListBusinesssInput input)
        {
            var model = DataAccess.Businesses.ListBusinesss(input);
            return new JsonXmlResult(model);
        }

        public ActionResult SearchBusinesss(Adams.Public.DataTransfer.Businesses.SearchBusinesssInput input)
        {
            var model = DataAccess.Businesses.SearchBusinesss(input);
            return new JsonXmlResult(model);
        }

        public ActionResult Business(Adams.Public.DataTransfer.Businesses.BusinessInput input)
        {
            var model = DataAccess.Businesses.Business(input);
            return new JsonXmlResult(model);
        }

        public ActionResult GetMemberBusinesss(Adams.Public.DataTransfer.Businesses.GetMemberBusinesssInput input)
        {
            input.MemberID = Api.Security.GetMemberIDFromToken(input.Token);
            var model = DataAccess.Businesses.GetMemberBusinesss(input);
            return new JsonXmlResult(model);
        }

        public ActionResult Renew(Adams.Public.DataTransfer.Businesses.RenewInput input)
        {
            input.MemberID = Api.Security.GetMemberIDFromToken(input.Token);
            var output = new Adams.Public.DataTransfer.FormOutput();

            var save = new Adams.Public.DataTransfer.Businesses.RenewSave();
            Shared.ObjectHelper.CopyObject(output, ref save);

            save.ExpiresOn = DateTime.Now.AddYears(1);

            DataAccess.Businesses.Renew(save);

            output.IsSaved = true;

            return new JsonXmlResult(output);
        }

        public ActionResult Remove(Adams.Public.DataTransfer.Businesses.RemoveInput input)
        {
            input.MemberID = Api.Security.GetMemberIDFromToken(input.Token);
            var output = new Adams.Public.DataTransfer.FormOutput();

            DataAccess.Businesses.Remove(input);

            output.IsSaved = true;

            return new JsonXmlResult(output);
        }
    }
}